package com.ship.control.search;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.ship.common.DateUtil;

/**
 * 日志
 * @author wqf
 * @version  Nov 24, 2011 11:55:45 AM
 */
public class ShipLogSearchCond extends SearchCond{
	
	/**
	 * 用户id
	 */
	protected Long userId;	
	
	/**
	 * 用户id
	 */
	protected Long shipInfoId;	
	
	private String shipName;
	
	private String item;
	
	public String getItem() {
		return item;
	}

	public void setItem(String item) {
		this.item = item;
	}

	public String getShipName() {
		return shipName;
	}

	public void setShipName(String shipName) {
		this.shipName = shipName;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getStartDate2() {
		return startDate2;
	}

	public void setStartDate2(Date startDate2) {
		this.startDate2 = startDate2;
	}

	private Date startDate;
	
	private Date startDate2;
	
	public Long getShipInfoId() {
		return shipInfoId;
	}

	public void setShipInfoId(Long shipInfoId) {
		this.shipInfoId = shipInfoId;
	}

	public ConditionPart getCondition(){
		ConditionPart cp=new ConditionPart();
		StringBuffer searchStr=new StringBuffer(" 1=1");
				
		if(null!=userId){
			searchStr.append(" and user.id=?");
			cp.getParams().add(userId);
		}
		if(null!=shipInfoId){
			searchStr.append(" and shipInfo.id=?");
			cp.getParams().add(shipInfoId);
		}
		
		if(StringUtils.isNotEmpty(shipName)){
			searchStr.append(" and shipInfo.shipName like ?");
			cp.getParams().add("%"+shipName+"%");
		}
		if(StringUtils.isNotEmpty(item)){
			searchStr.append(" and item like ?");
			cp.getParams().add("%"+item+"%");
		}
		//创建时间  开始
		if(null!=startDate){
			searchStr.append(" and startDate>=?");
			cp.getParams().add(startDate);
		}
		//创建时间  结束
		if(null!=startDate2){
			searchStr.append(" and endDate<=?");
			cp.getParams().add(DateUtil.getDateAfter(startDate2, 1));
		}
		cp.setExpression(searchStr.toString());
		return cp;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

}
